package top.malaoshi.ctrl.user;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.malaoshi.Constants;
import top.malaoshi.entity.Orders;
import top.malaoshi.entity.UserModel;
import top.malaoshi.service.OrderSrvImpl;
import top.malaoshi.vo.JsonResult;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/user/orders")
public class OrdersCtrl {

    @Resource
    private OrderSrvImpl srv;
    /**
     * 下订单
     */
    @RequestMapping("/order")
    public JsonResult order(Orders orders, HttpSession session){
        UserModel um=(UserModel)session.getAttribute(Constants.USER_INFO);
        JsonResult jr=new JsonResult();
        try {
            srv.save(orders,um);
            jr.setCode(0);
            jr.setMsg("购买成功！");
        }catch (Exception e){
            e.printStackTrace();
            jr.setCode(100);
            jr.setMsg("购买失败！");
        }
        return jr;
    }
}
